﻿using System;
using System.Collections.Generic;
using System.Text;
using WebApiV3.Data.Entity;
using WebApiV3.Domain.Enum;
using WebApiV3.Interface.Log;

namespace WebApiV3.Utils.Log
{
    public static class LogHelper
    {
        public static void Logger(this ILog log, Exception exception, LogsLevel logsLevel , int userId = 0)
        {
            var item = new Logs
            {
                LogLevel = (int)logsLevel,
                ShortMessage = exception.Message,
                FullMessage = exception.ToString(),
                UserId = userId
            };
            log.Insert(item);
        }
        //信息
        public static void Info(this ILog log, Exception exception ,int userId = 0)
        {
            Logger(log, exception, LogsLevel.信息, userId);
        }
        //调试
        public static void Debug(this ILog log, Exception exception, int userId = 0)
        {
            Logger(log, exception, LogsLevel.调试, userId);
        }
        //错误
        public static void Error(this ILog log, Exception exception, int userId = 0)
        {
            Logger(log, exception, LogsLevel.错误, userId);
        }
        //崩溃
        public static void Fatal(this ILog log, Exception exception, int userId = 0)
        {
            Logger(log, exception, LogsLevel.崩溃, userId);
        }
        //警告
        public static void Warn(this ILog log, Exception exception, int userId = 0)
        {
            Logger(log, exception, LogsLevel.警告, userId);
        }
    }
}
